﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using com.lover.astd.common.config;
using com.lover.astd.common.model;
using com.lover.astd.common;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.game.ui.server.impl.economy
{
    /// <summary>
    /// 祭祀服务
    /// </summary>
    class FeteServer : LogicServer
    {
        public FeteServer(MainForm frm) { _mainForm = frm; ServerName = ConfigStrings.S_Fete; ServerReadableName = ConfigStrings.SR_Fete; }
        public override void renderSettings()
        {
            Dictionary<string, string> conf = getConfig(ServerName);
            if (conf.Count == 0) return;
            MainForm frm = _mainForm;
            if (conf.ContainsKey(ConfigStrings.enabled))
            {
                frm.chk_fete_enable.Checked = conf[ConfigStrings.enabled].ToLower().Equals("true");
            }
            if(conf.ContainsKey(ConfigStrings.fete_gold))
            {
                string fete_golds = conf[ConfigStrings.fete_gold];
                string[] fete_goldstrs = fete_golds.Split(',');
                int gold = 0;
                if (fete_goldstrs.Length > 0) 
                {
                    Int32.TryParse(fete_goldstrs[0], out gold);
                    frm.num_fete_1.Value = gold;
                }
                if (fete_goldstrs.Length > 1)
                {
                    Int32.TryParse(fete_goldstrs[1], out gold);
                    frm.num_fete_2.Value = gold;
                }
                if (fete_goldstrs.Length > 2)
                {
                    Int32.TryParse(fete_goldstrs[2], out gold);
                    frm.num_fete_3.Value = gold;
                }
                if (fete_goldstrs.Length > 3)
                {
                    Int32.TryParse(fete_goldstrs[3], out gold);
                    frm.num_fete_4.Value = gold;
                }
                if (fete_goldstrs.Length > 4)
                {
                    Int32.TryParse(fete_goldstrs[4], out gold);
                    frm.num_fete_5.Value = gold;
                }
                if (fete_goldstrs.Length > 5)
                {
                    Int32.TryParse(fete_goldstrs[5], out gold);
                    frm.num_fete_6.Value = gold;
                }
            }
            
        }
        public override void saveSettings()
        {
            GameConfig conf = getConfig();
            MainForm frm = _mainForm;
            conf.setConfig(ServerName, ConfigStrings.enabled, frm.chk_fete_enable.Checked.ToString());
            string fete_gold = String.Format("{0},{1},{2},{3},{4},{5}",
                frm.num_fete_1.Value, frm.num_fete_2.Value, frm.num_fete_3.Value,
                frm.num_fete_4.Value, frm.num_fete_5.Value, frm.num_fete_6.Value);
            conf.setConfig(ServerName, ConfigStrings.fete_gold, fete_gold);
        }
        public override void loadDefaultSettings()
        {
            GameConfig conf = getConfig();
            conf.setConfig(ServerName, ConfigStrings.enabled, "true");
            conf.setConfig(ServerName, ConfigStrings.fete_gold, "2,0,0,2,2,6");
            renderSettings();
        }
    }
}
